// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_SYS_PERIOD
// * CreateDate    : 2013-08-28 11:00:58
// * Creater       : CodeSmith
// * LastChangeDate: 2013-08-28 11:00:58
// * LastChanger   : 2013-08-28 11:00:58
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;

namespace ESOL.Business.Sys
{
/// <summary>
    /// SysPeriod
    /// </summary>
    public partial class SysPeriodBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objSysPeriodEntity">Entity</param>
        /// <returns>Entity</returns>
        public static SysPeriodEntity GetSysPeriod(SysPeriodEntity objSysPeriodEntity)
        {
            return DataAccess.SelectSingle<SysPeriodEntity>(objSysPeriodEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objSysPeriodEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static SysPeriodEntity InsertSysPeriod(SysPeriodEntity objSysPeriodEntity)
        {
            objSysPeriodEntity.Id = Guid.NewGuid().ToString();
            DataAccess.Insert(objSysPeriodEntity);
            return objSysPeriodEntity;
        }

        public static bool InsertSysPeriod(List<SysPeriodEntity> objSysPeriodEntityList)
        {
            return DataAccess.Insert(objSysPeriodEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objSysPeriodEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateSysPeriod(SysPeriodEntity objSysPeriodEntity)
        {
            return DataAccess.Update(objSysPeriodEntity);
        }

        public static bool UpdateSysPeriod(List<SysPeriodEntity> objSysPeriodEntityList)
        {
            return DataAccess.Update<SysPeriodEntity>(objSysPeriodEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objSysPeriodEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteSysPeriod(SysPeriodEntity objSysPeriodEntity)
        {
            return DataAccess.Delete(objSysPeriodEntity);
        }

        public static bool DeleteSysPeriod(List<SysPeriodEntity> objSysPeriodEntityList)
        {
            return DataAccess.Delete<SysPeriodEntity>(objSysPeriodEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetSysPeriodAll()
        {
            return DataAccess.SelectAllDataSet<SysPeriodEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<SysPeriodEntity> GetSysPeriodAllList()
        {
            return DataAccess.SelectAll<SysPeriodEntity>();
        }
        #endregion


        #region Functions
        public static DataSet GetSysPeriodByFc(SysFcEntity sysFc)
        {
            string sql = "select * from sys_period where calendar_id='"+sysFc.Id+"'";
            return DataAccess.SelectDataSet(sql);
        }

        public static DataSet GetSysPeriodPageByFc(SysFcEntity sysFc, int pageIndex, int pageCount)
        {
            string sql = @"select top {0} *,(select count(1) from sys_period) as cnt
from sys_period
where calendar_id='{4}' and id not in (
    select top ({1}*({2}-1)) id from sys_period
    where calendar_id='{3}' order by year,month,day
) order by year,month,day";
            sql = string.Format(sql, pageCount, pageCount, pageIndex,sysFc.Id,sysFc.Id);
            return DataAccess.SelectDataSet(sql);
        }


        public static List<SysPeriodEntity> GetSysPeriodByMonth(int year, int month)
        {
            return DataAccess.Select<SysPeriodEntity>(new SysPeriodEntity { Year = year, Month = month });
        }
        #endregion
    }
	
	
}	

